<!--{include(pe_tpl('header.html'));}-->
<div class="wgw_box">
	<div class="wgw_btn"></div>
	<div class="mat20 font16 c666">你的购物车里还没有商品</div>
	<div class="g_btn"><a href="{$pe['host_root']}">去逛逛</a></div>
</div>
<div class="content" style="display:none">
<div class="dd_box">
	<div class="liucheng" style="margin-top:10px;">我的购物车</div>
	<div class="mat20">
		<form method="post" id="form">
		<div class="gouwuche">
			<table width="100%" border="0" cellspacing="0" cellpadding="0" class="gwc_tb">
			<tr>
				<th width="20"></th>
				<th width="60">商品图片</th>
				<th>商品信息</th>
				<th width="180"></th>
				<th width="160">单价(元)</th>
				<th width="120">数量</th>
				<th width="120">操作</th>
			</tr>
			<!--{foreach($info_list as $k=>$v):}-->
			<tr class="js_cart sel" val="{$v['cart_id']}">
				<td><input type="checkbox" checked="checked" readonly onclick="cart_select(this)" /></td>
				<td class="hotimg1"><img src="{pe_thumb($v['product_logo'], 100, 100)}" /></td>
				<td valign="top" style="text-align:left">
					<div style="width:350px; margin-top:10px;"><a href="{pe_url('product-'.$v['product_id'])}" target="_blank" class="font14 c888">{$v['product_name']}</a></div>
				</td>
				<td style="text-align:left;">
					<!--{if($v['prorule_name']):}-->
					<div class="c888"><!--{foreach(unserialize($v['prorule_name']) as $vv):}-->[{$vv['name']}：{$vv['value']}]&nbsp;&nbsp;<br /><!--{endforeach;}--></div>
					<!--{endif;}-->
				</td>
				<td class="num font14"><span class="money3">¥{$v['product_money']}</span></td>
				<td class="shuliang" style="padding-left:10px;">
					<span class="img1" onclick="cart_edit('-', '{$v['cart_id']}');"><i></i></span>
					<div class="shuliang_box"><input type="text" name="cart_{$v['cart_id']}" value="{$v['product_num']}" product_money="{$v['product_money']}" readonly /></div>
					<span class="img2" onclick="cart_edit('+', '{$v['cart_id']}');"><i></i></span>
				</td>
				<td><a href="javascript:;" onclick="cart_edit('del', '{$v['cart_id']}')">删除</a></td>
			</tr>
			<!--{endforeach;}-->
			</table>
		</div>
		<div class="ddtj_btn_box">
			<div class="fl"><a href="javascript:pe_open('back');">继续购物</a></div>
			<input type="hidden" name="pe_token" value="{$pe_token}" />
			<input type="hidden" name="pesubmit" />	
			<input type="button" id="order_btn" onclick="cart_submit()" value="结算" class="ddtj_btn" />
			<span class="fr">已选 <span class="font18 cfen num" id="order_num">1</span> 件商品， 合计（不含运费）：<span class="font18 num cfen"> ¥ <span id="order_money">{$money['order_money']}</span></span></span>
		</div>
		</form>
	</div>
</div>
</div>
<script type="text/javascript">
$(function(){
	cart_select('all');
})
//购物车选择
function cart_select(_this) {
	if (_this == 'all') {
		$(".js_cart").addClass("sel");
	}
	else {
		var js_cart = $(_this).parents(".js_cart");
		if (js_cart.hasClass("sel")) {
			js_cart.removeClass("sel");
			js_cart.find(":checkbox").removeAttr("checked");
		}
		else {
			js_cart.addClass("sel");
			js_cart.find(":checkbox").attr("checked", "checked");
		}
	}
	cart_callback();
}
//购物车修改
function cart_edit(type, cart_id) {
	var _this = $(":input[name='cart_"+cart_id+"']");
	if (type == 'del') {
		var num = 0;
	}
	else {
		var num = parseInt(_this.val());
		num = type == '+' ? num + 1 : (num >= 1 ? num - 1 : 0);
	}
	if (num == 0) {
		if (confirm('您确认要删除该商品吗?') == false) return;
	}
	$.getJSON("{$pe['host_root']}index.php", {"mod":"cart","act":"edit","id":cart_id,"num":num}, function(json){
		if (json.result) {
			_this.val(num);
			if (num == 0) _this.parents(".js_cart").remove();
			cart_callback();
		}
	})
}
//购物车回调
function cart_callback() {
	if ($(".js_cart").length == 0) {
		$(".wgw_box").show();
		$(".content").hide();
	}
	else {
		$(".wgw_box").hide();
		$(".content").show();	
	}
	var product_money = 0, product_num = 0, order_money = 0, order_num = 0;
	$(".js_cart.sel").each(function(){
		product_money = parseFloat($(":input[type='text']", this).attr("product_money"));
		product_num = parseInt($(":input[type='text']", this).val());
		order_money += product_money * product_num;
		order_num += product_num
	})
	$("#order_money").html(order_money.toFixed(1));
	$("#order_num").html(order_num);
}
//购物车结算
function cart_submit() {
	if (!$(".js_cart.sel").length) {
		pe_tip('请选择需要结算的商品');
		return false;
	} 
	var cart_arr = new Array();
	$(".js_cart.sel").each(function(){
		cart_arr.push($(this).attr("val"));
	})
	var cart_id = cart_arr.join(',');
	pe_open("{$pe['host_root']}index.php?mod=order&act=add&id="+cart_id);
}
</script>
<!--{include(pe_tpl('footer.html'));}-->